<?php
/*
 * @Author: lokei
 * @Date: 2022-10-05 16:07:41
 * @LastEditors: lokei
 * @LastEditTime: 2023-06-23 20:03:42
 * @Description: 
 */
namespace App\Http\Controllers\Store\GongShang;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Store\StoreModel;
use Illuminate\Http\Request;

class GongShangController extends Controller {
    public function get(Request $request) {
        $store = StoreModel::where('id', '=', $request->input('store_id'))->first();
        $res = ResultTool::success();
        $res['data']['is_company_audit'] = $store->is_company_audit;
        $res['data']['business_license'] = $store->business_license;
        $res['data']['name'] = $store->name;
        $res['data']['business_license_id'] = $store->business_license_id;
        $res['data']['registered_capital'] = $store->registered_capital;
        $res['data']['company_type'] = $store->company_type;
        $res['data']['credit_code'] = $store->credit_code;
        $res['data']['established_time'] = $store->established_time;
        $res['data']['operating_period_start'] = $store->operating_period_start;
        $res['data']['operating_period_finish'] = $store->operating_period_finish;
        $res['data']['operating_period_permanent'] = $store->operating_period_permanent;
        $res['data']['registered_address'] = $store->registered_address;
        $res['data']['legal_person'] = $store->legal_person;
        $res['data']['business_scope'] = $store->business_scope;
        $res['data']['business_scale'] = $store->business_scale;
        $res['data']['is_person_audit'] = $store->is_person_audit;
        $res['data']['idcard_img'] = $store->idcard_img;
        $res['data']['idcard_bg_img'] = $store->idcard_bg_img;
        $res['data']['idcard'] = $store->idcard;
        return $res;
    }

    public function set(Request $request) {
        $store = StoreModel::where('id', '=', $request->input('store_id'))->first();
        $store->is_company_audit = $request->input('is_company_audit');
        $store->business_license = $request->input('business_license');
        $store->name = $request->input('name');
        $store->business_license_id = $request->input('business_license_id');
        if($request->input('registered_capital') != null && $request->input('registered_capital') != 'null') {
            $store->registered_capital = $request->input('registered_capital');
        }
        $store->company_type = $request->input('company_type');
        $store->credit_code = $request->input('credit_code');
        if($request->input('established_time')) {
            $store->established_time = $request->input('established_time');
        }
        if($request->input('operating_period') != null && $request->input('operating_period') != 'null') {
            $store->operating_period = $request->input('operating_period');
        }
        if($request->input('operating_period_start') != null && $request->input('operating_period_start') != 'null' && $request->input('operating_period_start') != 'undefined') {
            $store->operating_period_start = $request->input('operating_period_start');
        }
        if($request->input('operating_period_finish') != null && $request->input('operating_period_finish') != 'null' && $request->input('operating_period_finish') != 'undefined') {
            $store->operating_period_finish = $request->input('operating_period_finish');
        }
        if($request->input('operating_period_permanent') != null && $request->input('operating_period_permanent') != 'null') {
            $store->operating_period_permanent = $request->input('operating_period_permanent');
        }
        $store->registered_address = $request->input('registered_address');
        $store->legal_person = $request->input('legal_person');
        $store->business_scope = $request->input('business_scope');
        $store->business_scale = $request->input('business_scale');
        $store->is_person_audit = $request->input('is_person_audit');
        $store->idcard_img = $request->input('idcard_img');
        $store->idcard_bg_img = $request->input('idcard_bg_img');
        $store->idcard = $request->input('idcard');
        $store->business_status = '0';
        $store->save();
        return ResultTool::success();
    }
}